<template>
  <div class="main" id="app">
    <div class="putIssue">
      <goBack></goBack>
      <scrollerEdit ref="scrollers" lock-x>
        <div class="put-questions">
          <div class="title flex-h">
            <span class="flex1 left">提问</span>
            <span class="flex1 right" @click="putQuestions">提交</span>
          </div>
          <div class="questions-body">
            <span class="sub-title">
              <i>*</i>
              <b>问题描述</b>
            </span>
            <textarea v-model="texts" class="textArea" cols="30" rows="10" placeholder="详细描述您的问题,以便专家更好的解答" v-on:blur="scrolltotop"></textarea>
            <span class="lenCount">{{ texts.length }}/200</span>
            <div class="expert-box flex-h">
              <span class="flex1 left"> </span>
              <span class="right" @click="isShowName = !isShowName">
                <b>
                  <i v-show="isShowName"></i>
                </b>
                <strong class>匿名隐私</strong>
              </span>
            </div>
            <div style="height:2rem"></div>
          </div>
        </div>
      </scrollerEdit>
    </div>
  </div>
</template>
<script>
// import { upload, getQuestionTypeList, quiz } from '~/api/identity'
import scrollerEdit from '~/components/scrollerEdit'
import goBack from '~/components/goBack'
import { putQuestions } from '~/api/school'
import ls from 'store2'
export default {
  components: {
    goBack,
    scrollerEdit,
  },
  data() {
    return {
      texts: '',
      isShowName: false,
      flag: false,
    }
  },
  mounted: function() {
    this.$visit('SubmitQuestions')
  },

  methods: {
    scrolltotop() {
      window.scroll(0, 0)
    },
    putQuestions() {
      if (!this.texts) {
        this.$vux.toast.text('请输入您的问题')
        return
      }
      if (this.flag) {
        this.$vux.toast.text('请不要重复提交')
        return
      }
      this.flag = true
      this.isShowName ? (this.anonymous = 2) : (this.anonymous = 1)
      let obj = {
        text: this.texts,
        user_id: ls.get('yxkData').userId,
        is_anonymous: this.anonymous,
      }
      putQuestions(this.$route.query.type, obj)
        .then((res) => {
          if (res.length === 0) {
            this.$vux.toast.text('提交成功')
          } else {
            this.$vux.toast.text('提交失败,请稍后重试')
          }
          this.flag = false
          this.$router.back()
        })
        .catch((error) => {
          this.flag = false
          this.$vux.toast.text('提交失败,请稍后重试')
        })
    },
  },
}
</script>
<style lang="less" type="text/less" scoped rel="stylesheet/less">
.putIssue {
  width: 100%;
  height: 100vh;
  background: #fff;
  .put-questions {
    width: 100%;
    height: auto;
    padding: 0 0.3rem;
    .title {
      width: 100%;
      height: 1rem;
      border-bottom: 0.01rem solid rgba(229, 232, 237, 1);
      span {
        font-size: 0.3rem;
        font-family: 'PingFangSC-Semibold', PingFangSC;
      }
      .left {
        color: #222;
      }
      .right {
        color: @mainColor;
        text-align: right;
      }
    }
    .questions-body {
      height: auto;
      padding-top: 0.1rem;
      .sub-title {
        display: block;
        i,
        b {
          font-size: 0.3rem;
        }
        i {
          color: #eb4e3f;
          margin-right: 0.05rem;
        }
      }
      .textArea {
        width: 100%;
        height: 3rem;
        outline: none;
        border: none;
        font-size: 0.3rem;
        display: block;
        margin-top: 0.2rem;
      }
      .lenCount {
        display: block;
        text-align: right;
        font-size: 0.24rem;
        color: #c7c7c7;
        margin-top: 0.2rem;
      }

      .expert-box {
        width: 100%;
        height: auto;
        padding-top: 0.2rem;
        margin-top: 0.2rem;
        border-top: 0.01rem solid rgba(229, 232, 237, 1);
        .left {
          b {
            display: inline-block;
            padding: 0.1rem 0.2rem;
            background: #f8f8f8;
            font-size: 0.26rem;
            border-radius: 0.1rem;
            color: #b3b3b3;
          }
        }
        .right {
          b {
            display: inline-block;
            width: 0.3rem;
            height: 0.3rem;
            border: 0.01rem solid #eaeaea;
            border-radius: 2px;
            vertical-align: middle;
            i {
              display: block;
              width: 0.2rem;
              height: 0.2rem;
              margin: 0.04rem auto;
              background: @mainColor;
            }
          }
          strong {
            font-size: 0.26rem;
            vertical-align: middle;
            margin-left: 0.1rem;
          }
        }
      }
    }
  }
}
</style>
